package com.example;

import org.openjdk.jol.info.ClassLayout;

/**
 * @author shanchong
 * @date 2021/4/20
 **/
public class Demo {


    public static void main(String[] args) throws InterruptedException {
        Demo demo = new Demo();
        new Thread(()->{
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("6." + ClassLayout.parseInstance(demo).toPrintable());
            synchronized (demo) {
                System.out.println("4." + ClassLayout.parseInstance(demo).toPrintable());
                demo.notify();
                System.out.println("5." + ClassLayout.parseInstance(demo).toPrintable());
            }
        }).start();
        System.out.println("3." + ClassLayout.parseInstance(demo).toPrintable());
        synchronized (demo) {
            try {
                System.out.println("1." + ClassLayout.parseInstance(demo).toPrintable());
                demo.wait();
                System.out.println("2." + ClassLayout.parseInstance(demo).toPrintable());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
//        lock();
    }

    public static synchronized void lock() throws InterruptedException {
        Demo.class.wait();
    }

}
